Skip to content

Conversation

@MiguelLZPF
Copy link
Contributor

Summary

  • ✅ Optimize test fixture deployment speed: 47s → 2s (96% improvement, 22.7x speedup)
  • ✅ Cherry-pick nominal value decimals feature from feat: nominal value decimals added to smart contracts #693
  • ✅ Cherry-pick duplicated fragments fix with TypeChain factory improvement
  • ✅ Refactor ERC20Permit test to use getDltTimestamp() helper
  • ✅ Preserve deploymentTime tracking in workflow output

Root Causes Fixed

1. Inefficient Batch Size in Tests (22s delay per config)

  • Fixture was using batchSize=2 instead of DEFAULT_BATCH_SIZE (15)
  • Created 23 batches instead of 3-4 batches per configuration
  • With 1000ms delays: 23 batches × 1000ms = 22s per config
  • Two configurations (equity + bond) = 44s total unnecessary delay

2. Unnecessary Network Delays on Instant-Mining Networks

  • 1000ms delays designed for real networks to prevent RPC overload
  • Hardhat/local networks process transactions instantly - delays are pure waste
  • Each deployment: 44 delays × 1000ms = 44 seconds of wasted time

Solutions Implemented

Network-Aware Batch Processing

  • Created isInstantMiningNetwork() helper (hardhat, local)
  • Skip delays on instant-mining networks
  • Optimized batch size: single batch (capped at 20 for gas limits) on instant networks
  • Real networks unchanged: still use batch size 15 with delays

Test Fixture Optimization

  • Fixed batch size from 2 → DEFAULT_BATCH_SIZE (15)
  • Reduces batches from 23 to 3-4 per configuration
  • Import DEFAULT_BATCH_SIZE for consistency

Additional Improvements

  • Refactored ERC20Permit test: use getDltTimestamp() helper (8 instances)
  • Preserved deploymentTime field in DeploymentOutput type
  • Added confirmations parameter propagation through domain modules
  • Fixed clearingActionsFacet undefined error using TypeChain factory

Performance Impact

# Before optimization:
npx hardhat test (infrastructure fixture) → 47 seconds

# After optimization:
npx hardhat test (infrastructure fixture) → 2 seconds

Result: 96% reduction in test deployment time, no functionality changes

Backward Compatibility

  • ✅ Real networks (hedera-testnet, hedera-mainnet) unchanged
  • ✅ Still use configurable batch sizes (default 15)
  • ✅ Still include 1000ms delays to prevent RPC overload
  • ✅ Gas limit safety: single-batch capped at 20 facets

Changeset

✅ Changeset included: .changeset/test-performance-optimization.md

@MiguelLZPF MiguelLZPF requested review from a team as code owners November 14, 2025 13:03
@MiguelLZPF MiguelLZPF requested a review from mgarbs November 14, 2025 13:03
@hedera-eng-infrastructure
Copy link

hedera-eng-infrastructure commented Nov 14, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@MiguelLZPF MiguelLZPF changed the title fix(contracts): optimize test fixture deployment speed (96% improvement) fix(contracts): optimize test fixture deployment speed Nov 14, 2025
@MiguelLZPF MiguelLZPF self-assigned this Nov 14, 2025
@MiguelLZPF MiguelLZPF added Contracts Changes related to the “contracts” module Bug A error that causes the feature to behave differently than what was expected based on design docs labels Nov 14, 2025
Dramatically improved contract test performance from 47 seconds to 2
seconds per fixture (22.7x speedup, 96% reduction in deployment time).
Root cause was inefficient batch processing during BLR configuration
creation in test environments.

Performance Impact:
- Infrastructure fixture: 47s to 2s (95.7% faster)
- Full test suite runtime significantly reduced
- No performance degradation on real networks

Root Causes Fixed:

1. Inefficient Batch Size in Tests (22s delay per config)
   - Fixture was using batchSize=2 instead of DEFAULT_BATCH_SIZE (15)
   - Created 23 batches instead of 3-4 batches per configuration
   - With 1000ms delays between batches: 23 × 1000ms = 22s per config
   - Two configurations (equity + bond) = 44s total unnecessary delay

2. Unnecessary Network Delays on Instant-Mining Networks
   - 1000ms delays designed for real networks (prevent RPC overload)
   - Hardhat/local networks process transactions instantly
   - Each deployment: 44 delays × 1000ms = 44 seconds of waste

Solutions Implemented:

1. Fixed Test Fixture Batch Size (infrastructure.fixture.ts)
   - Changed default from batchSize=2 to DEFAULT_BATCH_SIZE (15)
   - Reduces batches from 23 to 3-4 per configuration
   - Import DEFAULT_BATCH_SIZE from scripts for consistency

2. Network-Aware Batch Processing (blrConfigurations.ts)
   - Created isInstantMiningNetwork() to detect instant networks
   - Skip 1000ms delays on hardhat and local networks
   - Optimized batch size: single batch (capped at 20) on instant
   - Real networks unchanged: still use batching with delays

3. Network Detection Helper (networkConfig.ts)
   - Added isInstantMiningNetwork(): hardhat || local
   - Clear distinction: instant (hardhat, local) vs real (hedera)
   - hedera-local correctly treated as real network
   - Deprecated isLocalNetwork() in favor of clearer naming

4. Confirmations Parameter Propagation
   - Added confirmations to createEquityConfiguration()
   - Added confirmations to createBondConfiguration()
   - Test environments use 0 confirmations (instant)
   - Proper parameter flow: fixture → modules → operations

Additional Improvements:

5. Refactored ERC20Permit Test (erc20Permit.test.ts)
   - Replaced manual timestamp retrieval with getDltTimestamp()
   - 8 instances updated for cleaner, maintainable test code

6. Preserved Original deploymentTime Tracking
   - Restored deploymentTime field in DeploymentOutput type
   - Tracks total workflow execution time
   - Added to checkpoint conversion and test assertions

Files Modified:

Infrastructure & Operations:
- scripts/infrastructure/networkConfig.ts
- scripts/infrastructure/operations/blrConfigurations.ts
- scripts/infrastructure/checkpoint/utils.ts
- scripts/infrastructure/checkpoint/NullCheckpointManager.ts
- scripts/infrastructure/index.ts

Domain Modules:
- scripts/domain/equity/createConfiguration.ts
- scripts/domain/bond/createConfiguration.ts
- scripts/index.ts

Workflows:
- scripts/workflows/deploySystemWithNewBlr.ts
- scripts/workflows/deploySystemWithExistingBlr.ts

CLI Scripts:
- scripts/cli/hardhat.ts (preserved)
- scripts/cli/standalone.ts (preserved)

Tests:
- test/fixtures/infrastructure.fixture.ts
- test/contracts/unit/layer_1/ERC1400/ERC20Permit/erc20Permit.test.ts

Technical Notes:
- Gas Limit Safety: Single-batch optimization capped at 20 facets
- Backward Compatibility: Real networks unchanged
- Test Environment Detection: Uses hre.network.name
- Type Safety: All TypeScript types properly updated

Verification:
Before: npx hardhat test infrastructure.fixture.ts  # 47 seconds
After:  npx hardhat test infrastructure.fixture.ts  # 2 seconds

No functionality changes - pure performance optimization.

Signed-off-by: Miguel_LZPF <[email protected]>
Signed-off-by: Axel-IoBuilders <[email protected]>
Signed-off-by: Miguel_LZPF <[email protected]>
@MiguelLZPF MiguelLZPF force-pushed the fix/test-delays-create-configuration branch from 2e7d438 to 94e9c7f Compare November 14, 2025 13:10
The nominal value decimals feature (PR #693) was cherry-picked into this branch
but the mass-payout test mocks were not updated. This caused struct size mismatches
between the test asset mock implementations and the actual contract interfaces.

Changes:
- IAssetMock.sol: Added `uint8 nominalValueDecimals` field to both EquityDetailsData
  and BondDetailsData structs to match ATS contract interface definitions
- AssetMock.sol: Updated getBondDetails() to set nominalValueDecimals = 2
- AssetMock.sol: Implemented getEquityDetails() with proper struct initialization
  including all equity rights flags, currency, nominal value, and nominalValueDecimals

Impact: All 131 tests now pass. Test fixtures correctly represent contract state
without struct size mismatches.

Signed-off-by: Miguel_LZPF <[email protected]>
@MiguelLZPF MiguelLZPF force-pushed the fix/test-delays-create-configuration branch from 2e32269 to 8fe120d Compare November 17, 2025 07:51
@MiguelLZPF MiguelLZPF merged commit 8073a52 into develop Nov 17, 2025
12 checks passed
@MiguelLZPF MiguelLZPF deleted the fix/test-delays-create-configuration branch November 17, 2025 08:33
themariofrancia pushed a commit that referenced this pull request Dec 9, 2025
Signed-off-by: Miguel_LZPF <[email protected]>
Signed-off-by: Axel-IoBuilders <[email protected]>
themariofrancia pushed a commit that referenced this pull request Dec 10, 2025
Signed-off-by: Miguel_LZPF <[email protected]>
Signed-off-by: Axel-IoBuilders <[email protected]>
themariofrancia pushed a commit that referenced this pull request Dec 10, 2025
Signed-off-by: Miguel_LZPF <[email protected]>
Signed-off-by: Axel-IoBuilders <[email protected]>
Signed-off-by: Mario Francia <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug A error that causes the feature to behave differently than what was expected based on design docs Contracts Changes related to the “contracts” module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants